package com.itheima.redbaby.engine.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;

import com.alibaba.fastjson.JSON;
import com.itheima.redbaby.GloableParams;
import com.itheima.redbaby.bean.Invoice;
import com.itheima.redbaby.bean.OrderInfo;
import com.itheima.redbaby.engine.BaseEngine;
import com.itheima.redbaby.engine.InvoiceEngine;
import com.itheima.redbaby.engine.OrderEngine;
import com.itheima.redbaby.net.HttpUtil;

public class InvoiceEngineImpl extends BaseEngine implements InvoiceEngine {
	@Override
	public List<Invoice> getServerInvoice() {
		//1.读取response字段
		//2.判断是否为 checkout
		HttpUtil httpUtil=new HttpUtil();
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("response", "invoice");
		String userid=null;
		String json = httpUtil.sendPost(GloableParams.LZLURLCOMMON+GloableParams.LZLCONTENT, params, userid);
		try{
			JSONObject jsonObject=new JSONObject(json);
			String res = jsonObject.getString("response");//得到解析中的response信息
			if(res.equals("invoice")){
				String invoice = jsonObject.getString("invoice");
				List<Invoice> invoicelist = JSON.parseArray(invoice, Invoice.class);
				return invoicelist;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}//相当于服务器中map集合
		return null;
	}
}
